package com.xxx.mall.service.impl;

import com.xxx.mall.context.AuthUserContext;
import com.xxx.mall.mapper.AttachFileMapper;
import com.xxx.mall.model.AttachFileGroup;
import com.xxx.mall.mapper.AttachFileGroupMapper;
import com.xxx.mall.service.AttachFileGroupService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xxx.mall.vo.AttachFileGroupVO;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 邢晨旭
 * @since 2023-11-20
 */
@Service
public class AttachFileGroupServiceImpl extends ServiceImpl<AttachFileGroupMapper, AttachFileGroup> implements AttachFileGroupService {

    @Resource
    AttachFileMapper attachFileMapper;

    @Override
    public List<AttachFileGroupVO> queryList() {
        return baseMapper.queryList(AuthUserContext.get().getTenantId());
    }

    @Override
    public void saveGroup(AttachFileGroupVO attachFileGroupVO) {
        attachFileGroupVO.setShopId(AuthUserContext.get().getTenantId());
        baseMapper.save(attachFileGroupVO);
    }

    @Override
    public void updateGroup(AttachFileGroupVO attachFileGroupVO) {
        baseMapper.updateGroup(attachFileGroupVO);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deleteById(Long attachFileGroupId) {
        baseMapper.removeById(attachFileGroupId);
        attachFileMapper.updateBatchByGroupId(attachFileGroupId);
    }
}
